import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:library_base/base/base_app_state_page.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/dividing_line.dart';
import 'package:library_base/res/edge.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:library_base/widget/dialog/create_delivery_note_controller.dart';
import 'package:library_base/widget/image/local_image.dart';

class CreateDeliveryNoteDialog extends StatefulWidget {
  const CreateDeliveryNoteDialog({
    Key? key,
  }) : super(key: key);

  @override
  State<CreateDeliveryNoteDialog> createState() => _CreateDeliveryNoteDialogState();
}

class _CreateDeliveryNoteDialogState
    extends BaseState<CreateDeliveryNoteDialog, CreateDeliveryNoteController> {
  @override
  isListenLifeCycle() => false;

  @override
  void onCreate() {
    setNavigationBarVisible(false);
    setStatusBarVisible(false);
    setBackgroundColor(Colors.transparent);
  }

  @override
  Widget? getMainWidget(BuildContext context) {
    return Stack(
      children: [
        GestureDetector(onTap: () => Get.back()),
        GestureDetector(
          onTap: () {},
          child: Column(
            children: [
              SizedBox(height: 0.11.sh),
              Row(
                children: [
                  SizedBox(width: 0.06.sw),
                  Container(
                    width: 0.88.sw,
                    height: 0.63.sh,
                    decoration: rs8,
                    child: Column(
                      children: [
                        SizedBox(
                          height: 95.w,
                          width: double.infinity,
                          child: Stack(
                            children: [
                              Container(
                                  alignment: Alignment.center,
                                  child: Text(MultiLanguage.createADeliveryNote.tr,
                                      style: normalTextColor34)),
                              Positioned(
                                top: 10.w,
                                right: 0,
                                child: GestureDetector(
                                  onTap: () => Get.back(),
                                  child: Padding(
                                      padding: edgeAll24,
                                      child: LocalImage('common_close',
                                          package: Constant.packLib(), width: 26.r, height: 26.r)),
                                ),
                              )
                            ],
                          ),
                        ),
                        // gapH24,
                        line1,
                        Expanded(
                            child: SingleChildScrollView(
                          physics: const BouncingScrollPhysics(),
                          child: Column(
                            children: [
                              gapH24,
                              Row(children: [
                                Expanded(
                                    flex: 2,
                                    child: Text(MultiLanguage.commodityQuantity.tr,
                                        style: TextStyles.textNormal28, textAlign: TextAlign.end)),
                                Gaps.hGap24,
                                Expanded(
                                    flex: 7,
                                    child: Text('${baseGetxController!.commodityQuantity.value}'))
                              ]),
                              gapH24,
                              Row(children: [
                                Expanded(
                                    flex: 2,
                                    child: Text(MultiLanguage.freight.tr,
                                        style: TextStyles.textNormal28, textAlign: TextAlign.end)),
                                Gaps.hGap24,
                                Expanded(
                                    flex: 7,
                                    child: Text(
                                      '${baseGetxController!.freight.value == 0.0 ? '-' : baseGetxController!.freight.value} 元',
                                      style: TextStyles.eighthTextColor28,
                                    ))
                              ]),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseLoadingTime,
                                  title: MultiLanguage.loadingTime.tr,
                                  hint: MultiLanguage.pleaseSelectALoadingTime.tr,
                                  content: baseGetxController!.loadingTime),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseWarehouse,
                                  title: MultiLanguage.loadingWarehouse.tr,
                                  hint: MultiLanguage.pleaseSelectALoadingWarehouse.tr,
                                  content: baseGetxController!.warehouse.value != null
                                      ? baseGetxController!.warehouse.value!.whName
                                      : null),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseSupplier,
                                  title: MultiLanguage.carrier.tr,
                                  hint: MultiLanguage.pleaseSelectACarrier.tr,
                                  content: baseGetxController!.supplier.value != null
                                      ? baseGetxController!.supplier.value!.name
                                      : null),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseAccountRule,
                                  title: MultiLanguage.billingRules.tr,
                                  hint: MultiLanguage.pleaseSelectABillingRule.tr,
                                  content: baseGetxController!.accountRuleEntity.value != null
                                      ? baseGetxController!.accountRuleEntity.value!.ruleJoint
                                      : null),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseCar,
                                  title: MultiLanguage.numberPlate.tr,
                                  hint: MultiLanguage.pleaseSelectALicensePlateNumber.tr,
                                  content: baseGetxController!.car.value != null
                                      ? baseGetxController!.car.value!.carModelName
                                      : null),
                              gapH24,
                              buildItem(
                                  onTap: baseGetxController!.chooseDriver,
                                  title: MultiLanguage.driver.tr,
                                  hint: MultiLanguage.pleaseSelectADriver.tr,
                                  content: baseGetxController!.driver.value != null
                                      ? baseGetxController!.driver.value!.name
                                      : null),
                            ],
                          ),
                        )),
                        line1,
                        GradientButton(
                          ThemeUtil.getTheme(),
                          width: double.infinity,
                          height: 77.r,
                          margin: edgeV36H24 as EdgeInsets,
                          text: MultiLanguage.platoon.tr,
                          onPressed: baseGetxController!.loginEnabled.value
                              ? baseGetxController!.platoon
                              : null,
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ],
          ),
        )
      ],
    );
  }

  buildItem(
      {GestureTapCallback? onTap, required String title, required String hint, String? content}) {
    return Row(children: [
      Expanded(
          flex: 2, child: Text(title, style: TextStyles.textNormal28, textAlign: TextAlign.end)),
      Gaps.hGap24,
      Expanded(
          flex: 7,
          child: GestureDetector(
            onTap: onTap,
            child: Container(
                padding: edgeAll24,
                decoration: BoxDecoration(
                    borderRadius: const BorderRadius.all(Radius.circular(30.0)),
                    border:
                        Border.all(color: ThemeUtil.getTheme().secondaryTextColor(), width: 1.0)),
                child: Row(children: [
                  Expanded(
                      child: Text(content == null || content.isEmpty ? hint : content,
                          style: content == null || content.isEmpty
                              ? TextStyles.textSecondary28
                              : TextStyles.textNormal28)),
                  LocalImage('common_grey_rightward_arrow',
                      package: Constant.packLib(), width: 20.w, height: 20.w),
                ])),
          )),
      gapW24,
    ]);
  }

  @override
  CreateDeliveryNoteController? registerController() => Get.put(CreateDeliveryNoteController());
}
